<template>
    <div>
        <el-dialog title="添加小区" :visible.sync="dialogVisible" width="20%" :before-close="handleClose"
            center>
            <el-form ref="form" :model="form" label-width="80px" :rules="rules">
                <el-form-item label="uid" prop="pid">
                    <el-input v-model="form.pid" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="名称" prop="name">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="qu">取 消</el-button>
                <el-button type="primary" @click="add()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { addBuil } from '@/api/building'
export default {
    props: {
        dialogVisible: {
            type: Boolean,
            default: () => { }
        },
        pid: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            form: {
                pid: '',
                name: ""
            },
            rules:{
                name: [
                    { required: true, message: '请输入名称', trigger: 'blur' },
                ],
            }
        };
    },
    updated() {
        this.form.pid = this.$store.state.building.id
    },
    watch: {
        pid: {
            handler(val) {
                if (val) {
                    this.form.pid = val
                }
            }
        }
    },
    methods: {
        async add() {
            let res = await addBuil(this.form)
            if (res.errCode == 10000) {
                this.$message.success("添加成功")
            }
            this.$emit('isclose', false, true, {})
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    this.$emit('isclose', false)
                })
                .catch(_ => { });
        },
        qu() {
            this.$emit('isclose', false)
        }
    }
}
</script>

<style lang="less" scoped>

</style>